let vm = new Vue({
    el: '.main-content',
    data: function () {
        return {
            pageInfo: {},
            user: {},
            active: true,
            name: "全部",
            condition: {
                name: '',
            },
            setting: {
                data: {
                    simpleData: {
                        enable: true,
                        pIdKey: "parentId"
                    },

                }, callback: {
                    onClick: this.onClick
                },

                view: {
                    fontCss: this.fontCss
                }
            },
            nodes: []
        }
    },
    methods: {

        selectPage: function (pageNum = 1, pageSize = 5) {
            axios({
                url: `mapper/userList/selectPage/${pageNum}/${pageSize}`,
                params: this.condition
            }).then(response => {
                this.pageInfo = response.data.obj;
            }).catch(error => {
                console.log(error.msg)
            })

        },
        selectAll: function () {
            //查询全部：  1.清空查询条件对象值  2.调用selectPage
            this.condition = {
                name: ''
            };
            this.selectPage();
        },
        Details: function (user) {
            layer.obj = user;
            layer.open({
                type: 2,
                title: false,
                area: ['70%', '70%'],
                content: 'mapper/userList/Details',
            })
        },
        toUpdate: function () {
            layer.open({
                type: 2,
                title: false,
                area: ['70%', '70%'],
                content: 'mapper/userList/toUpdate',
            })
        },
        doDelete: function (user) {
            layer.msg('是否删除', {
                time: 20000, //20s后自动关闭
                btn: ['是', '否'],
                yes: () => {
                    //删除标记（0：正常；1：删除；2：审核；）
                    user.delFlag = "1";
                    axios({
                        url: "mapper/userList/doUpdate",
                        method: "post",
                        data: user,
                    }).then(response => {
                        layer.msg(response.data.msg)
                        this.selectPage();//刷新页面
                    }).catch(error => {
                        layer.msg(error.message)
                    });
                }
            });
        },

        initTree: function () {
            //初始化nodes数据
            axios({
                url: "mapper/office/selectAll"
            }).then(response => {
                this.nodes = response.data.obj;
                this.nodes[this.nodes.length] = {"id": 0, "name": "全部"};
                $.fn.zTree.init($("#pullDownTreeone"), this.setting, this.nodes);
            }).catch(error => {
                layer.msg(error.message)
            })

        },
        initTree2: function () {
            //初始化nodes数据
            axios({
                url: "mapper/office/selectAll"
            }).then(response => {
                this.nodes = response.data.obj;
                this.nodes[this.nodes.length] = {"id": 0, "name": "全部"};
                $.fn.zTree.init($("#pullDownTreetwo"), this.setting, this.nodes);
            }).catch(error => {
                layer.msg(error.message)
            })

        },
        onClick: function (event, treeld, treeNode) {
            this.name = treeNode.name;
            if (treeNode.id === 0) {
                //全部
                this.condition.oid = null;
            } else {
                //绑定查询条件
                this.condition.oid = treeNode.id;
            }

            //删除open
            $(".btn-group").removeClass("open");

        },
        search: function () {
            // 1.获取树对象
            // 2.调用getNodesByParamFuzzy(属性名,属性值,父节点id)模糊匹配节点
            let zTreeObj = $.fn.zTree.getZTreeObj("pullDownTreeone");
            let NodesByParamFuzzy = zTreeObj.getNodesByParamFuzzy("name", this.name, null);

            let array = zTreeObj.transformToArray(zTreeObj.getNodes());
            for (let i in array) {
                //设置高亮属性
                array[i].hightLight = false;
                //更新树对象上的节点信息，会自动触发显示回调
                zTreeObj.updateNode(array[i])
            }

            for (let i in NodesByParamFuzzy) {
                //设置高亮属性
                NodesByParamFuzzy[i].hightLight = true;
                //更新树对象上的节点信息，会自动触发显示回调
                zTreeObj.updateNode(NodesByParamFuzzy[i])
            }

        },
        search2: function () {
            // 1.获取树对象
            // 2.调用getNodesByParamFuzzy(属性名,属性值,父节点id)模糊匹配节点
            let zTreeObj = $.fn.zTree.getZTreeObj("pullDownTreetwo");
            let NodesByParamFuzzy = zTreeObj.getNodesByParamFuzzy("name", this.name, null);

            let array = zTreeObj.transformToArray(zTreeObj.getNodes());
            for (let i in array) {
                //设置高亮属性
                array[i].hightLight = false;
                //更新树对象上的节点信息，会自动触发显示回调
                zTreeObj.updateNode(array[i])
            }

            for (let i in NodesByParamFuzzy) {
                //设置高亮属性
                NodesByParamFuzzy[i].hightLight = true;
                //更新树对象上的节点信息，会自动触发显示回调
                zTreeObj.updateNode(NodesByParamFuzzy[i])
            }

        },
        fontCss: function (treeId, treeNode) {
            // 根据高亮标记设置高亮红色
            return treeNode.hightLight ? {"color": "red"} : {"color": "black"}

        },
        insert: function () {
            axios({
                url: "mapper/userList/insert",
                method: "post",
                data: this.user
            }).then(response => {
                if (response.data.success) {
                    //清空
                    this.user = {};
                    //切换
                    this.active = !this.active;
                    console.log(12346)
                }
                    layer.msg(response.data.msg)
            }).catch(error => {
                layer.msg(error.message)
            })
        },
        aa: function () {
            this.active = !this.active
        },
    },
    created: function () {
        this.selectPage();

    },
    mounted: function () {
        this.initTree();
        this.initTree2();
    }


});